#include<iostream>
#include<unistd.h>
#include<string.h>
#include <signal.h>




int gcout=0;
void die(int signo)
{
  std::cout<<"signal_id : "<<signo<<"   gcout: "<<gcout<<std::endl;
  exit(1);
}

int main()
{
  //int cnt=5;
  signal(SIGALRM,die);
  std::cout<<"闹钟开始"<<std::endl;

  int ret = alarm(2);
  std::cout<<ret<<std::endl;
  std::cout<<"闹钟结束"<<std::endl;
  
  while (true)
  {
    gcout++;
  }
  
/*   while (true)
  {
    signal(2,die);
  } */
  
  
/*   while(true)
  {
    cnt--;
    std::cout << "hahaha alive" << std::endl;
    if(cnt<0)
      abort();
  } */


  return 0;
}
